﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Text;
using InfoSoftGlobal;

public partial class ZHCX_TJB : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
    if (!Page.IsPostBack)
    {
      if (!ProjectPrivate.GetQX("30"))
      {
        Server.Transfer("~\\blank.aspx");
      }
      DataSet ds = CBSJ.GetYear();
      CommonUse.BindDDL(ds, "year", "year", DateTime.Now.Year.ToString(), ddlYear_trq);
      ddlMonth_trq.SelectedValue = DateTime.Now.ToString("yyyy-MM").Substring(5, 2);
      InitTable();
      CBL();
      SFL();
      CKL();
      InitFormat();
    }
  }
  protected void InitTable()
  {
    Init1();
    Init2();
    Init4();
    Init3();
    Init5();
    Init6();
    Init7();
    Init8();
    Init9();
  }
  protected void InitFormat()
  {
    format(a1);
    format(b1);
    format(c1);
    format(d1);
    format(e1);

    format(a2);
    format(b2);
    format(c2);
    format(d2);
    format(e2);

    format(a3);
    format(b3);
    format(c3);
    format(d3);
    format(e3);

    format(a4);
    format(b4);
    format(c4);
    format(d4);
    format(e4);

    format(a5);
    format(b5);
    format(c5);
    format(d5);
    format(e5);

    format(a6);
    format(b6);
    format(c6);
    format(d6);
    format(e6);

    format(a7);
    format(b7);
    format(c7);
    format(d7);
    format(e7);

    format(a8);
    format(b8);
    format(c8);
    format(d8);
    format(e8);

    format(a9);
    format(b9);
    format(c9);
    format(d9);
    format(e9);
  }
  protected void format(Label lb)
  {
    if (lb.Text != "---")
      lb.Text = string.Format("{0:n}", Convert.ToDecimal(lb.Text));
  }
  protected void Init1()
  {
    a1.Text = "0"; b1.Text = "0"; c1.Text = "0"; d1.Text = "0"; e1.Text = "0";
    SqlDataReader dr = KHXX.GetXTYH(ddlYear_trq.SelectedValue, ddlMonth_trq.SelectedValue, "");
    while (dr.Read())
    {
      if (dr["khjb"].ToString() == "A")
        a1.Text = dr["a"].ToString();
      if (dr["khjb"].ToString() == "B")
        b1.Text = dr["a"].ToString();
      if (dr["khjb"].ToString() == "C")
      {
        if (dr["ic"].ToString() == "是")
          c1.Text = dr["a"].ToString();
        if (dr["ic"].ToString() == "否")
          d1.Text = dr["a"].ToString();
      }
    }
    dr.Close();
    e1.Text = (Convert.ToInt32(a1.Text) + Convert.ToInt32(b1.Text) + Convert.ToInt32(c1.Text) +
      Convert.ToInt32(d1.Text)).ToString();
  }
  protected void Init2()
  {
    a2.Text = "0"; b2.Text = "0"; c2.Text = "0"; d2.Text = "0"; e2.Text = "0";
    SqlDataReader dr = KHXX.GetXTYH(ddlYear_trq.SelectedValue, ddlMonth_trq.SelectedValue, "1");
    while (dr.Read())
    {
      if (dr["khjb"].ToString() == "A")
        a2.Text = dr["a"].ToString();
      if (dr["khjb"].ToString() == "B")
        b2.Text = dr["a"].ToString();
      if (dr["khjb"].ToString() == "C")
      {
        if (dr["ic"].ToString() == "是")
          c2.Text = dr["a"].ToString();
        if (dr["ic"].ToString() == "否")
          d2.Text = dr["a"].ToString();
      }
    }
    dr.Close();
    e2.Text = (Convert.ToInt32(a2.Text) + Convert.ToInt32(b2.Text) + Convert.ToInt32(c2.Text) +
      Convert.ToInt32(d2.Text)).ToString();
  }
  protected void Init3()
  {
    a3.Text = "0"; b3.Text = "0"; c3.Text = "---"; d3.Text = "0"; e3.Text = "0";
    a3.Text = (Convert.ToInt32(a1.Text) - Convert.ToInt32(a4.Text)).ToString();
    b3.Text = (Convert.ToInt32(b1.Text) - Convert.ToInt32(b4.Text)).ToString();
    d3.Text = (Convert.ToInt32(d1.Text) - Convert.ToInt32(d4.Text)).ToString();
    e3.Text = (Convert.ToInt32(a3.Text) + Convert.ToInt32(b3.Text) +
      Convert.ToInt32(d3.Text)).ToString();
  }
  protected void Init4()
  {
    a4.Text = "0"; b4.Text = "0"; c4.Text = "---"; d4.Text = "0"; e4.Text = "0";
    SqlDataReader dr = CBSJ.GetCBYH(ddlYear_trq.SelectedValue, ddlMonth_trq.SelectedValue);
    while (dr.Read())
    {
      if (dr["khjb"].ToString() == "A")
        a4.Text = dr["a"].ToString();
      if (dr["khjb"].ToString() == "B")
        b4.Text = dr["a"].ToString();
      if (dr["khjb"].ToString() == "C")
      {
        if (dr["ic"].ToString() == "是")
          c4.Text = dr["a"].ToString();
        if (dr["ic"].ToString() == "否")
          d4.Text = dr["a"].ToString();
      }
    }
    dr.Close();
    e4.Text = (Convert.ToInt32(a4.Text) + Convert.ToInt32(b4.Text) +
      Convert.ToInt32(d4.Text)).ToString();
  }
  protected void Init5()
  {
    a5.Text = "0"; b5.Text = "0"; c5.Text = "0"; d5.Text = "0"; e5.Text = "0";
    SqlDataReader dr = CBSJ.GetWCSQL(ddlYear_trq.SelectedValue, ddlMonth_trq.SelectedValue);
    while (dr.Read())
    {
      if (dr["khjb"].ToString() == "A")
        a5.Text = dr["a"].ToString();
      if (dr["khjb"].ToString() == "B")
        b5.Text = dr["a"].ToString();
      if (dr["khjb"].ToString() == "C")
      {
        if (dr["ic"].ToString() == "是")
          c5.Text = dr["a"].ToString();
        if (dr["ic"].ToString() == "否")
          d5.Text = dr["a"].ToString();
      }
    }
    dr.Close();
    e5.Text = (Convert.ToInt32(a5.Text) + Convert.ToInt32(b5.Text) + Convert.ToInt32(c5.Text) +
      Convert.ToInt32(d5.Text)).ToString();
  }
  protected void Init6()
  {
    a6.Text = "0"; b6.Text = "0"; c6.Text = "0"; d6.Text = "0"; e6.Text = "0";
    SqlDataReader dr = JFSJ.GetYSFYH(ddlYear_trq.SelectedValue, ddlMonth_trq.SelectedValue);
    while (dr.Read())
    {
      if (dr["khjb"].ToString() == "A")
        a6.Text = dr["a"].ToString();
      if (dr["khjb"].ToString() == "B")
        b6.Text = dr["a"].ToString();
      if (dr["khjb"].ToString() == "C")
      {
        if (dr["ic"].ToString() == "是")
          c6.Text = dr["a"].ToString();
        if (dr["ic"].ToString() == "否")
          d6.Text = dr["a"].ToString();
      }
    }
    dr.Close();
    e6.Text = (Convert.ToInt32(a6.Text) + Convert.ToInt32(b6.Text) + Convert.ToInt32(c6.Text) +
      Convert.ToInt32(d6.Text)).ToString();
  }
  protected void Init7()
  {
    a7.Text = "0"; b7.Text = "0"; c7.Text = "0"; d7.Text = "0"; e7.Text = "0";
    SqlDataReader dr = JFSJ.GetWCSF(ddlYear_trq.SelectedValue, ddlMonth_trq.SelectedValue);
    while (dr.Read())
    {
      if (dr["khjb"].ToString() == "A")
        a7.Text = dr["a"].ToString();
      if (dr["khjb"].ToString() == "B")
        b7.Text = dr["a"].ToString();
      if (dr["khjb"].ToString() == "C")
      {
        if (dr["ic"].ToString() == "是")
          c7.Text = dr["a"].ToString();
        if (dr["ic"].ToString() == "否")
          d7.Text = dr["a"].ToString();
      }
    }
    dr.Close();
    e7.Text = (Convert.ToDouble(a7.Text) + Convert.ToDouble(b7.Text) + Convert.ToDouble(c7.Text) +
      Convert.ToDouble(d7.Text)).ToString();
  }
  protected void Init8()
  {
    a8.Text = "0"; b8.Text = "0"; c8.Text = "---"; d8.Text = "0"; e8.Text = "0";
    a8.Text = (Convert.ToInt32(a4.Text) - Convert.ToInt32(a6.Text)) < 0 ? "0" : (Convert.ToInt32(a4.Text) - Convert.ToInt32(a6.Text)).ToString();
    b8.Text = (Convert.ToInt32(b4.Text) - Convert.ToInt32(b6.Text)) < 0 ? "0" : (Convert.ToInt32(b4.Text) - Convert.ToInt32(b6.Text)).ToString();
    d8.Text = (Convert.ToInt32(d4.Text) - Convert.ToInt32(d6.Text)) < 0 ? "0" : (Convert.ToInt32(d4.Text) - Convert.ToInt32(d6.Text)).ToString();
    e8.Text = (Convert.ToInt32(a8.Text) + Convert.ToInt32(b8.Text) +
      Convert.ToInt32(d8.Text)).ToString();
  }
  protected void Init9()
  {
    a9.Text = "0"; b9.Text = "0"; c9.Text = "---"; d9.Text = "0"; e9.Text = "0";
    SqlDataReader dr = CBSJ.GetWJQF(ddlYear_trq.SelectedValue, ddlMonth_trq.SelectedValue);
    while (dr.Read())
    {
      if (dr["khjb"].ToString() == "A")
        a9.Text = dr["a"].ToString();
      if (dr["khjb"].ToString() == "B")
        b9.Text = dr["a"].ToString();
      if (dr["khjb"].ToString() == "C")
      {
        if (dr["ic"].ToString() == "是")
          c9.Text = dr["a"].ToString();
        if (dr["ic"].ToString() == "否")
          d9.Text = dr["a"].ToString();
      }
    }
    dr.Close();
    e9.Text = (Convert.ToDouble(a9.Text) + Convert.ToDouble(b9.Text) +
      Convert.ToDouble(d9.Text)).ToString();
  }

  protected void CBL()
  {
    SqlDataReader dr = CBSJ.GetCBL(ddlYear_trq.SelectedValue);
    StringBuilder strXML = new StringBuilder();
    strXML.Append("<graph caption='抄表率'bgColor ='#EFEFEF'showNames='1' baseFont='宋体' baseFontSize='12' subCaption='' decimalPrecision='0'numberSuffix='%25' pieSliceDepth='30' formatNumberScale='0'>");
    while (dr.Read())
    {
      strXML.Append("<set name='" + dr["yf"].ToString() + "' value='" + dr["cbl"].ToString() + "' />");
    }
    dr.Close();
    strXML.Append("</graph>");
    ltCBL.Text = FusionCharts.RenderChartHTML("../FCF/Column3D.swf", "", strXML.ToString(), "myNext", "1000", "200", false);
  }
  protected void SFL()
  {
    SqlDataReader dr = JFSJ.GetSFL(ddlYear_trq.SelectedValue);
    StringBuilder strXML = new StringBuilder();
    strXML.Append("<graph caption='收费率'showNames='1' baseFont='宋体' baseFontSize='12' subCaption='' decimalPrecision='0' numberSuffix='%25' pieSliceDepth='30' formatNumberScale='0'>");
    while (dr.Read())
    {
      strXML.Append("<set name='" + dr["yf"].ToString() + "' value='" + dr["sfl"].ToString() + "' />");
    }
    dr.Close();
    strXML.Append("</graph>");
    ltSFL.Text = FusionCharts.RenderChartHTML("../FCF/Column2D.swf", "", strXML.ToString(), "myNext", "1000", "200", false);
  }
  protected void CKL()
  {
    SqlDataReader dr = CBSJ.GetCKL(ddlYear_trq.SelectedValue);
    StringBuilder strXML = new StringBuilder();
    strXML.Append("<graph caption='充卡率'showNames='1' baseFont='宋体' baseFontSize='12' subCaption='' decimalPrecision='0' numberSuffix='%25' pieSliceDepth='30' formatNumberScale='0'>");
    while (dr.Read())
    {
      strXML.Append("<set name='" + dr["yf"].ToString() + "' value='" + dr["ckl"].ToString() + "' />");
    }
    dr.Close();
    strXML.Append("</graph>");
    ltCKL.Text = FusionCharts.RenderChartHTML("../FCF/Column2D.swf", "", strXML.ToString(), "myNext", "1000", "200", false);
  }
  protected void btnQuery_Click(object sender, EventArgs e)
  {
    InitTable();
    InitFormat();
    CBL();
    SFL();
    CKL();
  }
}